<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>计算三个数字的大小，按从小到大顺序输出</title>
</head>

<body>
    <!-- 计算三个数字的大小，按从小到大顺序输出 -->
    <input type="text">
    <input type="text">
    <input type="text">
    <button>从小到大排序</button>
    <p></p>
</body>
<script>
    (function () {
        let inps = document.querySelectorAll('input');
        let btn = document.querySelector('button');
        let p = document.querySelector('p');

        btn.addEventListener('click', function () {
            let num1 = inps[0].value * 1;
            let num2 = inps[1].value * 1;
            let num3 = inps[2].value * 1;

            p.innerHTML = rank(num1, num2, num3);
        })

        function rank() {
            var arr = [...arguments];
            for (var i = 0; i < arr.length; i++) {
                for (var j = 0; j < arr.length - 1 - i; j++) {
                    if (arr[j] > arr[j + 1]) {
                        var temp = arr[j];
                        arr[j] = arr[j + 1];
                        arr[j + 1] = temp;
                    }
                }
            }
            return arr;
        }

    })();
</script>

</html>